<template>
    <div>
        <div id="userAdd">
            <el-radio-group v-model="labelPosition" size="small">
            </el-radio-group>
            <div style="margin: 20px;"></div>
            <el-form :label-position="labelPosition" label-width="180px">
                <el-form-item label="账号account">
                    <el-input v-model="user.account"></el-input>
                </el-form-item>
                <el-form-item label="密码password">
                    <el-input v-model="user.password"></el-input>
                </el-form-item>
                <el-form-item label="姓名name">
                    <el-input v-model="user.name"></el-input>
                </el-form-item>
                <el-form-item label="权限role">
                    <el-radio-group v-model="user.role">
                        <el-radio label="admin">管理员Admin</el-radio>
                        <el-radio label="teacher">教师Teacher</el-radio>
                        <el-radio label="student">学生Student</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">立即创建</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<style lang="less">

</style>

<script>
import { userAdd } from '@/api/user'
import { Message } from 'element-ui'

export default {
  data () {
    return {
      labelPosition: 'right',
      user: {
        account: '',
        password: '',
        name: '',
        role: ''
      }
    }
  },
  methods: {
    onSubmit () {
      if (this.user.account === '' ||
      this.user.password === '' ||
      this.user.name === '' ||
      this.user.role === '') {
        Message.error('信息不完整')
        return
      }
      console.log(this.user)
      userAdd(this.user)
      Message.success('添加陈功')
    }
  }
}
</script>
